package com.bjpowernode.mvc.convert;

import com.bjpowernode.db.domain.Recharge;
import com.bjpowernode.mvc.model.vo.RechargeVO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.Named;

import java.util.List;

/**
 * 充值记录转换接口，使用mapstruct实现
 */
@Mapper(componentModel = "spring")
public interface RechargeConvert {

    List<RechargeVO> convertRechargeVOList(List<Recharge> rechargeList);


    @Mappings({
            @Mapping(target = "id", source = "id"),
            @Mapping(target = "result", source = "rechargeStatus", qualifiedByName = "getStatusText"),
            @Mapping(target = "rechargeMoney", source = "rechargeMoney"),
            @Mapping(target = "rechargeTime", source = "rechargeTime", dateFormat = "yyyy-MM-dd HH:mm:ss"),
    })
    RechargeVO convertRechargeVO(Recharge recharge);

    @Named("getStatusText")
    default String translateStatus(Integer status) {
        String result = "-";
        if (status == null) {
            return result;
        }

        result = switch (status) {
            case 0 -> "充值中";
            case 1 -> "充值成功";
            case 2 -> "充值失败";
            default -> "充值状态未知";
        };
        return result;
    }
}
